﻿using System;
using System.Runtime.Serialization;

namespace lucere.index.read
{
    /// <summary>
    /// A Term represents a word from text.  This is the unit of search.  It is
    /// composed of two elements, the text of the word, as a string, and the name of
    /// the field that the text occurred in, an interned string.
    /// 
    /// Note that terms may represent more than words from text fields, but also
    /// things like dates, email addresses, urls, etc.  
    /// </summary>
    public interface ITerm : IComparable<ITerm>, ISerializable
    {
        /// <summary>
        /// Gets or sets the field of this term, an interned string.
        /// The field indicates the part of a document which this 
        /// term came from. 
        /// </summary>
        /// <returns></returns>
        string Field { get; set; }

        /// <summary>
        /// Gets or sets the text of this term.  In the case of words, this is simply the 
        /// text of the word.  In the case of dates and other types, this is an
        /// encoding of the object as a string.  
        /// </summary>
        string Text { get; set; }

        /// <summary>
        /// Optimized construction of new Terms by reusing same field as this Term.
        /// Avoids field.intern() overhead         
        /// </summary>
        /// <param name="text">The text of the new term (field is implicitly same as this Term instance)</param>
        /// <returns>A new Term</returns>
        ITerm CreateTerm(string text);
    }
}
